home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / ucs4swapped.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  860 b   |  34 lines

  1. /*
  2.  * UCS-4-SWAPPED = UCS-4-INTERNAL with inverted endianness
  3.  */
  4.  
  5. static int
  6. ucs4swapped_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  7. {
  8.   /* This function assumes that 'unsigned int' has exactly 32 bits. */
  9.   if (sizeof(unsigned int) != 4) abort();
  10.  
  11.   if (n >= 4) {
  12.     unsigned int x = *(const unsigned int *)s;
  13.     x = (x >> 24) | ((x >> 8) & 0xff00) | ((x & 0xff00) << 8) | (x << 24);
  14.     *pwc = x;
  15.     return 4;
  16.   }
  17.   return RET_TOOFEW(0);
  18. }
  19.  
  20. static int
  21. ucs4swapped_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  22. {
  23.   /* This function assumes that 'unsigned int' has exactly 32 bits. */
  24.   if (sizeof(unsigned int) != 4) abort();
  25.  
  26.   if (n >= 4) {
  27.     unsigned int x = wc;
  28.     x = (x >> 24) | ((x >> 8) & 0xff00) | ((x & 0xff00) << 8) | (x << 24);
  29.     *(unsigned int *)r = x;
  30.     return 4;
  31.   } else
  32.     return RET_TOOSMALL;
  33. }
  34.